import { Injectable } from '@nestjs/common';
import { from } from 'rxjs';
import { RequestServer } from '../request';
import { UserinfoService } from '@/servers/redis/userinfo/userinfo.service';


@Injectable()
export class InwuRequestApiService {

    url = 'www.yisiqi168.com';
    port = 8080;
    constructor(
        private requestServer: RequestServer,
        private userinfoService: UserinfoService
    ) {

    }

    /**
     * 获取头部
     */
    getHeaders(token) {
        return {
            Accept: 'application/json, text/plain',
            'Content-Type': 'application/json;charset=UTF-8',
            'X-Authorization': 'Bearer ' + token,
        }
    }

    /**
     * GET方法
     * @param path 
     * @param params 
     * @param token 
     */
    async get(path: string, params: any, token?: string): Promise<any> {
        let headers = this.getHeaders(token);
        return this.requestServer.requestApi('get', this.url, this.port, headers, path, params);
    }

    /**
     * POST方法
     * @param path 
     * @param params 
     * @param token 
     */
    async post(path: string, params: any, token?: string): Promise<any> {
        let headers = this.getHeaders(token);
        return this.requestServer.requestApi('post', this.url, this.port, headers, path, params);
    }

    /**
    * delete方法 
    * @param path
    * @param params
    * @param token
    */
    async delete(path: string, params: any, token?: string): Promise<any> {
        params['returnNull']=true;
        let headers = this.getHeaders(token);
        return this.requestServer.requestApi('delete', this.url, this.port, headers, path, params);
    }

}
